﻿//-----------------------------------------------------------------------
// <copyright file="VisibilityAnimationStateHelper.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.ViewModels
{
    using System.Windows;

    using DomainObjects;

    /// <summary>
    /// Helper methods for the VisibilityAnimationState 
    /// </summary>
    public static class VisibilityAnimationStateHelper
    {
        /// <summary>
        /// Convert to a Visibility 
        /// </summary>
        /// <param name="state">the state to convert</param>
        /// <returns>a visibility</returns>
        public static Visibility ToVisibility(this VisibilityAnimationState state)
        {
            if (state == VisibilityAnimationState.Showing || state == VisibilityAnimationState.Shown || state == VisibilityAnimationState.Hiding)
            {
                return Visibility.Visible;
            }
            else if (state == VisibilityAnimationState.Collapsed)
            {
                return Visibility.Collapsed;
            }
            else
            {
                throw new ChatBoxException("Invalid VisibilityAnimationState" + state);
            }
        }

        /// <summary>
        /// True if the state indicates visible
        /// </summary>
        /// <param name="state">the state to convert</param>
        /// <returns>Is it visible</returns>
        public static bool IsVisibleState(this VisibilityAnimationState state)
        {
            return state == VisibilityAnimationState.Showing || state == VisibilityAnimationState.Shown;
        }

        /// <summary>
        /// Convert boolean to a VisibilityAnimationState
        /// </summary>
        /// <param name="value">the value to convert</param>
        /// <returns>a VisibilityAnimationState</returns>
        public static VisibilityAnimationState ToVisibilityAnimationState(this bool value)
        {
            if (value)
            {
                return VisibilityAnimationState.Shown;
            }
            else
            {
                return VisibilityAnimationState.Hiding;
            }
        }
    }
}
